package com.swh.xbsc.controller;

import com.swh.xbsc.entity.Result;
import com.swh.xbsc.entity.User;
import com.swh.xbsc.service.ArticleService;
import com.swh.xbsc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * @Author: swh
 * @Description:
 * @Date: 2020/11/17 20:49
 * @Version: 1.0
 */
@RestController
@RequestMapping("/mapper/user")
public class UserController {

    @Autowired
    UserService service;

    @RequestMapping("")
    public ModelAndView index() {
        return new ModelAndView("/user.html");
    }

    @RequestMapping("selectPage/{pageNum}/{pageSize}")
    public Result selectPage(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize,
                             @RequestParam Map<String, Object> map) {
        return new Result(service.selectPage(pageNum, pageSize, map));
    }

    @RequestMapping("selectPage2/{pageNum}/{pageSize}")
    public Result selectPage2(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize,
                             @RequestParam Map<String, Object> map) {
        return new Result(service.selectPage(pageNum, pageSize, map));
    }

    @RequestMapping(value = "toUpdate")
    public ModelAndView toUpdate(){
        return new ModelAndView("/user_detail.html");
    }

    @RequestMapping(value = "doUpdate",method = RequestMethod.POST)
    public Result doUpdate(@RequestBody User user){
        return new Result(service.updateByPrimaryKeySelective(user));
    }

}
